/*
 * Screens.java
 *
 * Created on Sekmadienis, 2006, Rugs�jo 17, 10.10
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package keitykla;

import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Screens
{
    private static SettingsDisplay SETTINGS_DISPLAY;
    private static AboutDisplay ABOUT_DISPLAY;
    private static InfoDisplay INFO_DISPLAY;
    private static NewCurrencyDisplay NEW_CURRENCY_DISPLAY;
    private static FlexConvertDisplay FLEX_CONVERT_DISPLAY;
    private static FlexCurrencySeletDisplay FLEX_CURRENCY_DISPLAY;
    private static DownloadProgressDisplay DOWNLOAD_PROGRESS_DISPLAY;
    private static Settings SETTINGS;
    private static SetHashtable SET_HASHTABLE;
    private static MIDlet midlet;
    private static ChoiceGroup currList;
    private static Waitting WAITTING;
    private static Error ERROR;
    
//-----------------------MIDlet------------------------------------------------------        
    public static MIDlet getMIDlet()
    {
	return midlet;
    }
    public static void setMIDlet(MIDlet m)
    {
	midlet=m;
    }

//-----------------------SettingsDisplay----------------------------------------------    
    public static Waitting getWaitting()
    {
        if(WAITTING==null)
        {
           WAITTING=new Waitting();
        }
        return WAITTING;
    }
    public static void showWaitting()
    {
        Display.getDisplay(midlet).setCurrent(getWaitting().getDisplayable());
    }    
    
//-----------------------SettingsDisplay----------------------------------------------    
    public static Error getError()
    {
        if(ERROR==null)
        {
           ERROR=new Error();
        }
        return ERROR;
    }
    public static void showError()
    {
        Display.getDisplay(midlet).setCurrent(getError().getDisplayable());
    }     
    
//-----------------------SettingsDisplay----------------------------------------------    
    public static SettingsDisplay getSettingsDisplay()
    {
        if(SETTINGS_DISPLAY==null)
        {
           SETTINGS_DISPLAY=new SettingsDisplay();
        }
        return SETTINGS_DISPLAY;
    }
    public static void showSettings()
    {
        Display.getDisplay(midlet).setCurrent(getSettingsDisplay().getDisplayable());
    }
    
//-----------------------AboutDisplay----------------------------------------------    
    public static AboutDisplay getAboutDisplay()
    {
        if(ABOUT_DISPLAY==null)
        {
           ABOUT_DISPLAY=new AboutDisplay();
        }
        return ABOUT_DISPLAY;
    }
    public static void showAbout()
    {
        Display.getDisplay(midlet).setCurrent(getAboutDisplay().getDisplayable());
    }    
    
//-----------------------InfoDisplay----------------------------------------------    
    public static InfoDisplay getInfoDisplay()
    {
//        if(INFO_DISPLAY==null)
//        {
           INFO_DISPLAY=new InfoDisplay();
//        }
        return INFO_DISPLAY;
    }
    public static void showInfo()
    {
        Display.getDisplay(midlet).setCurrent(getInfoDisplay().getDisplayable());
    }     
//-----------------------NewCurrencyDisplay----------------------------------------------        
    public static NewCurrencyDisplay getNewCurrencyDisplay()
    {
        if(NEW_CURRENCY_DISPLAY==null)
        {
           NEW_CURRENCY_DISPLAY=new NewCurrencyDisplay();
        }
        return NEW_CURRENCY_DISPLAY;
    }
    public static void showNewCurrency()
    {
        Display.getDisplay(midlet).setCurrent(getNewCurrencyDisplay().getDisplayable());
    }
//----------------------FlexConvertDisplay---------------------------------------------        
    public static FlexConvertDisplay getFlexConvertDisplay()
    {
        if(FLEX_CONVERT_DISPLAY==null)
        {
            try {
                FLEX_CONVERT_DISPLAY=new FlexConvertDisplay();
            } catch (UnsupportedEncodingException ex) {
                ex.printStackTrace();
            }
        }
        return FLEX_CONVERT_DISPLAY;
    }
    public static void showFlexConvert()
    {
        Display.getDisplay(midlet).setCurrent(getFlexConvertDisplay().getDisplayable());
    }
//------------------------FlexCurrencySeletDisplay---------------------------------------        
    public static FlexCurrencySeletDisplay getFlexCurrencySeletDisplay()
    {
        if(FLEX_CURRENCY_DISPLAY==null)
        {
           FLEX_CURRENCY_DISPLAY=new FlexCurrencySeletDisplay();            
        }
        return FLEX_CURRENCY_DISPLAY;
    }
    public static void showFlexCurrencySelect()
    {
        Display.getDisplay(midlet).setCurrent(getFlexCurrencySeletDisplay().getDisplayable());
    }
//-----------------------DownloadProgressDisplay------------------------------------------        
    public static DownloadProgressDisplay getDownloadProgressDisplay()
    {
        if(DOWNLOAD_PROGRESS_DISPLAY==null)
        {
           DOWNLOAD_PROGRESS_DISPLAY=new DownloadProgressDisplay();
        }
        return DOWNLOAD_PROGRESS_DISPLAY;
    }
    public static void showDownloadProgresst()
    {
        Display.getDisplay(midlet).setCurrent(getDownloadProgressDisplay().getDisplayable());
    }
    
//-----------------------DownloadProgressDisplay------------------------------------------   
    
    public static SetHashtable getSetHashtable()
    {
        if(SET_HASHTABLE==null)
        {
          SET_HASHTABLE=new SetHashtable();
        }
        return SET_HASHTABLE;
    }
    
//-----------------------DownloadProgressDisplay------------------------------------------  
    
    public static Settings getSettings()
    {
        if(SETTINGS==null)
        {
           SETTINGS=new Settings();
        }
        return SETTINGS;
    }    
      
//-----------------------------Screens-----------------------------------------------------        
    private Screens()
    {
    }
    
//----------------------------------------------------------------------------    
    public static void saveList(Currency curr)
    {
        currList = getList();
        String cur_code_name = null;
        cur_code_name = ""+curr.getCode()+" "+curr.getName();
        if(Integer.parseInt(curr.getChanged())==1 )
           try
           {
              currList.append(cur_code_name,Image.createImage("/hand_2.png")) ;
           }
           catch (IOException ex) 
           {
              ex.printStackTrace();
           }
        else
           try
           {
              currList.append(cur_code_name, null) ;    
           }
           catch(NullPointerException ee)
           {
               ee.printStackTrace();
           }
        Screens.setList(currList);
    }    
    
//---------------------------------------------------------------------------
    
    public static void setList(ChoiceGroup currList)
    {
        currList=currList;
    }
    
//---------------------------------------------------------------------------
    
    public static ChoiceGroup getList()
    {
        if(currList==null)
            currList = new ChoiceGroup("Valiutos", Choice.EXCLUSIVE);
        return currList;        
    }   
}
